package com.asiainfo.complier.editor;

import com.asiainfo.complier.format.CodeLine;

public class SmartIndent {
	private LineEditor editor;
	private int step;

	public SmartIndent(LineEditor editor) {
		this.editor = editor;
	}

	public int getIndent(int pos) {
		char startCaret = '{';
		char endCaret = '}';
		step = 1;
		String allText = editor.getText();
		for (int i = 0; i <= pos; i++) {
			char c = allText.charAt(i);
			if (c == startCaret)
				step++;
			else if (c == endCaret)
				step--;
		}
		return step;

	}

	@Override
	public String toString() {
		return "\n" + CodeLine.ToString(step);
	}

}
